﻿using System.Drawing;

using Storm.TextEditor.Editor;

namespace Storm.TextEditor.Parser.Objects
{
    /// <summary>
    /// Represents a word in a Row.
    /// </summary>
    public sealed class Word
    {
        #region Fields

        private Row row = null;
        private Segment segment = null;
        private Pattern pattern = null;

        private WordType type = WordType.Word;

        private TextStyle style = null;
        private Color errorColor = Color.Red;
        private Color warningColor = Color.DarkGreen;

        private bool hasError = false;
        private bool hasWarning = false;

        private string text = "";

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the parent Row of the Word.
        /// </summary>
        public Row Row
        {
            get { return row; }
            set { row = value; }
        }

        /// <summary>
        /// Gets or sets the Segment of the Word.
        /// </summary>
        public Segment Segment
        {
            get { return segment; }
            set { segment = value; }
        }

        /// <summary>
        /// Gets or sets the Pattern of the Word.
        /// </summary>
        public Pattern Pattern
        {
            get { return pattern; }
            set { pattern = value; }
        }

        /// <summary>
        /// Gets or sets what WordType the Word is.
        /// </summary>
        public WordType Type
        {
            get { return type; }
            set { type = value; }
        }

        /// <summary>
        /// Gets or sets the TextStyle of the Word.
        /// </summary>
        public TextStyle Style
        {
            get { return style; }
            set { style = value; }
        }

        /// <summary>
        /// Gets or sets the color of errors.
        /// </summary>
        public Color ErrorColor
        {
            get { return errorColor; }
            set { errorColor = value; }
        }

        /// <summary>
        /// Gets or sets the color of warnings.
        /// </summary>
        public Color WarningColor
        {
            get { return warningColor; }
            set { warningColor = value; }
        }

        /// <summary>
        /// Gets or sets whether the Word has an error.
        /// </summary>
        public bool HasError
        {
            get { return hasError; }
            set { hasError = value; }
        }

        /// <summary>
        /// Gets or sets whether the Word has a warning.
        /// </summary>
        public bool HasWarning
        {
            get { return hasWarning; }
            set { hasWarning = value; }
        }

        /// <summary>
        /// Gets or sets the text of the Word.
        /// </summary>
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        /// <summary>
        /// Gets the index of the word in the parent Row.
        /// </summary>
        public int Index
        {
            get { return this.row.IndexOf(this); }
        }

        /// <summary>
        /// Gets the column where the word starts on the containing Row.
        /// </summary>
        public int Column
        {
            get
            {
                int x = 0;

                foreach (Word word in this.Row)
                {
                    if (word == this)
                        return x;

                    x += word.text.Length;
                }

                return -1;
            }
        }

        #endregion

        /// <summary>
        /// Initializes a new instance of Word.
        /// </summary>
        public Word()
        {
        }
    }
}
